package com.yanqu.road.entity.banquet;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.banquet.invitation.BanquetChildInvitation;
import com.yanqu.road.entity.banquet.invitation.BanquetCrossInvitation;
import com.yanqu.road.entity.banquet.invitation.BanquetEstateInvitation;
import com.yanqu.road.entity.banquet.invitation.BanquetMarryInvitation;
import com.yanqu.road.entity.enums.eBanquetInfoType;
import com.yanqu.road.entity.enums.eBanquetInvitationType;

import java.util.Objects;

/**
 * 用户宴会邀请帖
 */
public class UserBanquetInvitation extends DataObject {

    /**
     * 唯一标示
     */
    private String iId;

    private long userId;

    /**
     * 请帖类型
     */
    private int type;

    /**
     * 请帖信息
     */
    private String info;

    /**
     * 获得时间
     */
    private long createTime;

    /**
     * 过期时间
     */
    private long overTime;

    private boolean isUsed;

    private long useTime;


    public String getiId() {
        return iId;
    }

    public void setiId(String iId) {
        if(!iId.equals(this.iId)) {
            this.iId = iId;
            setUpdateOption();
        }
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if(this.userId != userId) {
            this.userId = userId;
            setUpdateOption();
        }
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        if(this.type != type) {
            this.type = type;
            setUpdateOption();
        }
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        if(!info.equals(this.info)) {
            this.info = info;
            setUpdateOption();
        }
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        if(this.createTime != createTime) {
            this.createTime = createTime;
            setUpdateOption();
        }
    }

    public long getOverTime() {
        return overTime;
    }

    public void setOverTime(long overTime) {
        if(this.overTime != overTime) {
            this.overTime = overTime;
            setUpdateOption();
        }
    }


    public boolean isUsed() {
        return isUsed;
    }

    public void setUsed(boolean used) {
        if(this.isUsed != used){
            this.isUsed = used;
            setUpdateOption();
        }
    }

    public Object getInvitation() {
        if(getType() == eBanquetInvitationType.MarryInvitation.getValue()){
            return JSON.parseObject(getInfo(), BanquetMarryInvitation.class);
        }else if(getType() == eBanquetInvitationType.ChildInvitation.getValue()){
            return JSON.parseObject(getInfo(), BanquetChildInvitation.class);
        }else if(getType() == eBanquetInvitationType.EstateInvitation.getValue()){
            return JSON.parseObject(getInfo(), BanquetEstateInvitation.class);
        }else if(getType() == eBanquetInvitationType.CrossBanquet1Invitation.getValue()){
            return JSON.parseObject(getInfo(), BanquetCrossInvitation.class);
        }else if(getType() == eBanquetInvitationType.CrossBanquet2Invitation.getValue()){
            return JSON.parseObject(getInfo(), BanquetCrossInvitation.class);
        }else if(getType() == eBanquetInvitationType.CrossBanquet3Invitation.getValue()){
            return JSON.parseObject(getInfo(), BanquetCrossInvitation.class);
        }else if(getType() == eBanquetInvitationType.CrossBirthdayInvitation.getValue()){
            return JSON.parseObject(getInfo(), BanquetCrossInvitation.class);
        }
        return null;
    }

    public long getUseTime() {
        return useTime;
    }

    public void setUseTime(long useTime) {
        if (!Objects.equals(this.useTime, useTime)) {
            this.useTime = useTime;
            setUpdateOption();
        }
    }
}
